package com.feixiang.service.impl;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.feixiang.bean.User;
import com.feixiang.dao.UserDao;
import com.feixiang.service.UserService;

@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private UserDao userDao;
	@Transactional 
	public boolean addUser(User user) {
		return this.userDao.addUser(user)>0?true:false;
	}
	@Transactional
	public List<User> getUserList() {
		try {
			return this.userDao.getAllUsers();
		} catch (Exception e) {
			System.out.println("111");
			return null;
		}
	}
	public User findUserByName(String name) {
		return this.userDao.findUserByName(name);
	}
	public User getCurrentUser() {
		if(SecurityUtils.getSubject() == null) {
            return null;
        }
        return (User) SecurityUtils.getSubject().getPrincipal();
	}

}
